package com.tank.util;

import org.springframework.context.ApplicationContext;

import com.tank.bean.Notice;
import com.tank.bean.User;
import com.tank.service.NoticeService;
import com.tank.service.impl.NoticeServiceImpl;

public class NoticeUtil {
	
	private static NoticeService ns;
	private static Notice n=new Notice(TankUtil.getCurrentUser(),TankUtil.getCurrentUser(),"");
	
	static{
		init(ApplicationContextUtil.getContext());
	}
	
	public static void init(){
		ns=new NoticeServiceImpl();
	}
	public static void init(ApplicationContext ctx) {
		ns=(NoticeService) ctx.getBean("noticeService");		
	}
	
	public static void buddy(){
		n.setType(n.Buddy);
		n.setContent("#link:master#关注你了，<a href=\"buddy/fans\">查看</a>.");
		ns.addNotice(n);
	}
	
	public static void comment(){
		n.setType(n.Comment);
		n.setContent("#link:master#评论你了，<a href=\"buddy/fans\">查看</a>.");
		ns.addNotice(n);
	}
	
	public static void message(){
		n.setType(n.Message);
		n.setContent("#link:master#私信你了，<a href=\"buddy/fans\">查看</a>.");
		ns.addNotice(n);
	}
	public static void buddy(User master, User target) {
		n.setMaster(master);
		n.setTarget(target);
		
	}
	public static void addBuddy(User master, User target) {
		n=new Notice();
		n.setType(n.Buddy);
		n.setMaster(master);
		n.setTarget(target);
		n.setContent("#link:master#关注你了，<a href=\"buddy/fans\">查看</a>.");
		ns.addNotice(n);
		
	}
	public static void removeBuddy(User master, User target) {
		n=new Notice();
		n.setType(n.Buddy);
		n.setMaster(master);
		n.setTarget(target);
		ns.removeNotice(n);
	}
	
	public static void addAt(User master, User target){
		n=new Notice();
		n.setType(n.At);
		n.setMaster(master);
		n.setTarget(target);
		n.setContent("#link:master#提到你了，<a href=\"home?item.content=at\">查看</a>.");
		ns.addNotice(n);
	}


	
}
